<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ page import="java.util.*"%>
	<%@ page import="goods.*"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ include file="/Dmyna/admin/head.jsp"%>
<c:set var="WEB_ROOT" value="/Dmyna" />

<!-- 게시물 수 -->
<%!static int PAGE_SIZE = 20; //페이지당 20개%> 

<!--  -->
<%
	String pageNum = request.getParameter("page");
	if (pageNum == null) pageNum = "1";
	int currentPage = Integer.parseInt(pageNum);
	GoodsManager goodsmanager = GoodsManager.getInstance();
	int count = goodsmanager.count();
	int totalPageCount = 0;
	int startrow = 0, endRow = 0;
	if (count > 0) {
		totalPageCount = count / PAGE_SIZE;
		if (count % PAGE_SIZE > 0) totalPageCount++;
		startrow = (currentPage - 1) * PAGE_SIZE;
		endRow = currentPage * PAGE_SIZE;
	}
	List<GoodsItem> goodslist = goodsmanager.selectList(startrow, PAGE_SIZE);
%>

<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div
					style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;"
					align="center">::&nbsp;&nbsp;상품 관리&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>

<!--  -->
<c:set var="list" value="<%=goodslist%>" />
<table width="900" border="1" align="center" cellpadding="1" cellspacing="2" bordercolor="#f0f0f0">
	<tr>
		<!-- 전체게시물수 표시 -->
		<td colspan="8" height=25 align="right"><%=count %> 개의 상품이 있습니다.</td>
	</tr>
	<tr align="center" height="30">
		<td><font style="font-size: 10pt;">상품 코드</font></td>
		<td><font style="font-size: 10pt;">상품 이름</font></td>
		<td><font style="font-size: 10pt;">원가</font></td>
		<td><font style="font-size: 10pt;">할인가</font></td>
		<td><font style="font-size: 10pt;">할인여부</font></td>
		<td><font style="font-size: 10pt;">전시여부</font></td>
		<td><font style="font-size: 10pt;">상세정보</font></td>
		<td><font style="font-size: 10pt;">수정/삭제</font></td>
	</tr>
	
	<c:if test="${empty list }">
		<tr>
			<td bgcolor="#f0f0f0" colspan="8" height="100" align="center">등록된상품이 없습니다.</td>
		</tr>
	</c:if> 
	
	<c:if test="${!empty list }">
 	<c:forEach var="goods" items="${list }" >
	<tr bgcolor="#f0f0f0">
		<td align="center">${goods.gs_code }</td>
		<td align="left">${goods.gs_name }</td>
		<td align="right">${goods.gs_org_price }</td>
		<td align="right">${goods.gs_sale_price }</td>
		<td align="center">${goods.gs_sale_chk }</td>
		<td align="center">${goods.gs_display_chk }</td>
		<td align="center"><a href="goodsView.jsp?gs_code=${goods.gs_code }">상세정보</a></td>
		<td align="center"><a href="goodsUpdate.jsp?gs_code=${goods.gs_code }">[수정]</a>
								<a href="goodsDelete.jsp?gs_code=${goods.gs_code }">[삭제]</a>
		</td>
	</tr>
	


	</c:forEach>
	</c:if>
	<tr>
		<td colspan='7' height=25 align=center>
			<div class="board_page">

				<!--페이지 번호 시작-->
				<c:set var="count" value="<%=Integer.toString(count)%>" />
				<c:set var="PAGE_SIZE" value="<%=Integer.toString(PAGE_SIZE)%>" />
				<c:set var="currentPage" value="<%=Integer.toString(currentPage)%>" />
				<c:if test="${count > 0 }">

					<c:set var="pageCount"
						value="${count / PAGE_SIZE + (count % PAGE_SIZE == 0 ? 0 : 1) }" />
					<c:set var="startPage"
						value="${currentPage - (currentPage % 10 == 0 ? 10:(currentPage % 10)) + 1 }" />
					<c:set var="endPage" value="${startPage + 9 }" />
					<c:if test="${endPage > pageCount }">
						<c:set var="endPage" value="${pageCount }" />
					</c:if>

					<!-- 처음버튼 -->
					<c:if test="${startPage > 1  }">
						<a href="javascript:goPage(${startPage})"> <img
							src='${WEB_ROOT }/img/bbs/page_begin.gif' border='0'
							align='absmiddle' title='처음'>&nbsp;
						</a>
					</c:if>

					<!-- 이전버튼 -->
					<c:if test="${startPage > 10  }">
						<a href="javascript:goPage(${startPage-10 })"> <img
							src='${WEB_ROOT }/img/bbs/page_prev.gif' border='0'
							align='absmiddle' title='이전'>&nbsp;
						</a>
					</c:if>

					<!-- 숫자표시 -->
					<c:forEach var="pageNo" begin="${startPage }" end="${endPage }">
						<c:if test="${currentPage == pageNo }">
							<font size="4">
						</c:if>
						<a href="javascript:goPage(${pageNo })">${pageNo }&nbsp;</a>
						<c:if test="${currentPage == pageNo }">
							</font>
						</c:if>
					</c:forEach>

					<!-- 다음버튼 -->
					<c:if test="${endPage < pageCount  }">
						<a href="javascript:goPage(${startPage+10 })"> <img
							src='${WEB_ROOT }/img/bbs/page_next.gif' border='0'
							align='absmiddle' title='다음'>&nbsp;
						</a>
					</c:if>

					<!-- 맨끝버튼 -->
					<c:if test="${startPage > 1  }">
						<a
							href="javascript:goPage(<fmt:formatNumber value="${endPage}" pattern="#"/>)">
							<img src='${WEB_ROOT }/img/bbs/page_end.gif' border='0'
							align='absmiddle' title='맨끝'>
						</a>
					</c:if>
				</c:if>
				<!--페이지 번호 종료-->

			</div>
		</td>
		<td colspan="1" align="center">
		<a href="goodsWrite.jsp">[상품 등록]</a></td>
	</tr>
	
	<!-- <tr>
		<td colspan="7" align="right">
		<a href="goodsWrite.jsp">[상품 등록]</a></td>
	</tr> -->

</table>

<script language="javaScript">
function goPage(pageNo){
	document.move.action="goodsList.jsp";
	document.move.page.value = pageNo;
	document.move.submit();
}

</script>
<form name="move" method="post">
<input type="hidden" name="page" value="${currentPage }" />
</form>


<%@ include file="/Dmyna/admin/tail.jsp"%>
